package cn.foolishbird.crow.core.util;

import com.google.common.base.CaseFormat;
import org.apache.commons.lang3.StringUtils;

/**
 * 基于guava实现驼峰和下划线相互转换
 *
 * @author luohongtu
 * @date 2023/1/31
 */
public final class VariableUtils {

    private VariableUtils() {

    }

    /**
     * 下划线，转换成首字母大写
     * @param underline
     * @return
     */
    public static String underline2CamelCase(String underline) {
        if (StringUtils.isBlank(underline)) {
            return null;
        }
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underline);
    }

    /**
     * 首字母大写，转换成下划线
     * @param cameCase
     * @return
     */
    public static String cameCase2Underline(String cameCase) {
        if (StringUtils.isBlank(cameCase)) {
            return null;
        }
        return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, cameCase);
    }

}
